* Analysis data
use "$data/variables_foranalysis.dta", clear

*use "$data/01data.dta", clear

********************************************
**** 1. TIME PREFERENCES
********************************************

**
* Questionnaire: Staircase block (time preferences)
* Starts with intro question Q194
/* Choices are t1 to t31
t1 Would you rather receive $100 today or $153.80 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t1 = 2
t2 Would you rather receive $100 today or $125.40 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t2 = 2
t3 Would you rather receive $100 today or $112.40 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
Display This Question:
If t3 = 2
t4 Would you rather receive $100 today or $106.10 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t4 = 2
t5 Would you rather receive $100 today or $103.00 in 12 months?    
o	Today  (1) 
o
If t4 = 1
t6 Would you rather receive $100 today or $109.20 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t3 = 1
t7 Would you rather receive $100 today or $118.80 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t7 = 1
t8 Would you rather receive $100 today or $122.10 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t7 = 2
t9 Would you rather receive $100 today or $115.60 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t2 = 1
t10 Would you rather receive $100 today or $139.20 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t10 = 2
t11 Would you rather receive $100 today or $132.30 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t11 = 2
t12 Would you rather receive $100 today or $128.80 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t11 = 1
t13 Would you rather receive $100 today or $135.70 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t10 = 1
t14 Would you rather receive $100 today or $146.40 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t14 = 2
t15 Would you rather receive $100 today or $142.80 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t14 = 1
t16 Would you rather receive $100 today or $150.10 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t1 = 1
t17 Would you rather receive $100 today or $185.00 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t17 = 1
t18 Would you rather receive $100 today or $201.60 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t18 = 2
t19 Would you rather receive $100 today or $193.20 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t19 = 1
t20 Would you rather receive $100 today or $197.40 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t19 = 2
t21 Would you rather receive $100 today or $189.10 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t18 = 1
t22 Would you rather receive $100 today or $210.30 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t22 = 1
t23 Would you rather receive $100 today or $214.60 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t22 = 2
t24 Would you rather receive $100 today or $205.90 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t17 = 2
t25 Would you rather receive $100 today or $169.00 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t25 = 2
t26 Would you rather receive $100 today or $161.30 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t26 = 2
t27 Would you rather receive $100 today or $157.50 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t26 = 1
t28 Would you rather receive $100 today or $165.10 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t25 = 1
t29 Would you rather receive $100 today or $176.90 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t29 = 2
t30 Would you rather receive $100 today or $172.90 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
If t29 = 1
t31 Would you rather receive $100 today or $180.90 in 12 months?    
o	Today  (1) 
o	In 12 months  (2) 
End of Block: Falk time staircase
*/

* Create vars with amounts of later payment
gen sct_amt_12months1=153.80
gen sct_amt_12months2=125.40
gen sct_amt_12months3=112.40
gen sct_amt_12months4=106.10
gen sct_amt_12months5=103.00
gen sct_amt_12months6=109.20
gen sct_amt_12months7=118.80
gen sct_amt_12months8=122.10
gen sct_amt_12months9=115.60
gen sct_amt_12months10=139.20
gen sct_amt_12months11=132.30
gen sct_amt_12months12=128.80
gen sct_amt_12months13=135.70
gen sct_amt_12months14=146.40
gen sct_amt_12months15=142.80
gen sct_amt_12months16=150.10
gen sct_amt_12months17=185.00
gen sct_amt_12months18=201.60
gen sct_amt_12months19=193.20
gen sct_amt_12months20=197.40
gen sct_amt_12months21=189.10
gen sct_amt_12months22=210.30
gen sct_amt_12months23=214.60
gen sct_amt_12months24=205.90
gen sct_amt_12months25=169.00
gen sct_amt_12months26=161.30
gen sct_amt_12months27=157.50
gen sct_amt_12months28=165.10
gen sct_amt_12months29=176.90
gen sct_amt_12months30=172.90
gen sct_amt_12months31=180.90

* Label these later payment amount variables
forvalues i=1/31 {
label var sct_amt_12months`i' "Amount in 12 months (time preferences, staircase)"
}

* Code variables that record individual choices. In raw data 
* 1 means respondent picked payment today and 
* 2 means respondent picked later payment (in 12 months)
* Convert into binary indicator: 0 if today, 1 if later payment chosen

forvalues i=1/31 {
gen sct_choice_later`i'=.
replace sct_choice_later`i'=0 if t`i'=="Today"
replace sct_choice_later`i'=1 if t`i'=="In 12 months"
lab var sct_choice_later`i' "Choice: later payment (time preferences-staircase)"
}


*********************
* 2. RISK PREFERENCES
*********************
* Generate time and risk preference measures
/* Falk (2016 et al. "The Preference Survey Module: A Validated
Instrument for Measuring Risk, Time, and Social
Preferences"): 
- Use average of switching row
"6 As is common for this type of elicitation methods, 
some subjects exhibit multiple switching points. 
We observe that 86 individuals switch more than once 
from preferring the lottery to the safe payment in either of 
the two lottery choices experiments, 36 of them have multiple 
switch points in both experiments. For subjects who make that 
kind of inconsistent choices, we calculate the average switching 
row in each choice table and construct the experimental measure of 
risk aversion as the mean of the two averages."

"7 In the discounting experiments, we observe that around 7 percent
of subjects switch more than once from preferring the early payment 
to the late payment. For these subjects we construct the experimental 
measure by taking the mean of the average switching row in the two 
experiments involving intertemporal choices."*/
* 

/*
Q163 Please imagine the following situation: 
You can choose between a sure payment and a lottery. 
The lottery gives you a 50 percent chance of receiving $300. 
With an equally high chance you receive nothing. 
Now imagine you had to choose between the lottery and a sure payment. 
We will present to you five different situations.
The lottery is the same in all situations. 
The sure payment is different in every situation.    

r1                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $160 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r1 = 2

r2                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $80 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r2 = 2

r3                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $40 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r3 = 1

r4                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $60 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 

Display This Question:
If r4 = 1

r5                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $70 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r4 = 2

r6                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $50 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r3 = 2

r7                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $20 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r7 = 1

r8                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $30 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r7 = 2

r9                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $10 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r2 = 1

r10                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $120 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r10 = 2

r11                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $100 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r11 = 2

r12                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $90 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r11 = 1

r13                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $110 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r10 = 1

r14                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $140 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r14 = 1

r15                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $150 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r14 = 2

r16                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $130 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r1 = 1

r17                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $240 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r17 = 2

r18                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $200 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r18 = 2

r19                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $180 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r19 = 1

r20                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $190 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r19 = 2

r21                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $170 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r18 = 1

r22                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $220 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r22 = 1

r23                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $230 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r22 = 2
r24                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $210 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r17 = 1
r25                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $280 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r25 = 2
r26                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $260 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r26 = 1
r27                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $270 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r26 = 2
r28                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $250 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r25 = 1
r29                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $300 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r29 = 2
r30                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $290 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
Display This Question:
If r29 = 1
r31                   What would you prefer: a 50 percent chance of winning $300 when at the same time there is 50 percent chance of winning nothing, or would you rather have the amount of $310 as a sure payment?          
o	Lottery  (1) 
o	Sure payment  (2) 
*/

* Generate values of sure payment
* Lottery is always: 50% of $300
gen sct_risk_sure1=160
gen sct_risk_sure2=80
gen sct_risk_sure3=40
gen sct_risk_sure4=60
gen sct_risk_sure5=70
gen sct_risk_sure6=50
gen sct_risk_sure7=20
gen sct_risk_sure8=30
gen sct_risk_sure9=10
gen sct_risk_sure10=120
gen sct_risk_sure11=100
gen sct_risk_sure12=90
gen sct_risk_sure13=110
gen sct_risk_sure14=140
gen sct_risk_sure15=150
gen sct_risk_sure16=130
gen sct_risk_sure17=240
gen sct_risk_sure18=200
gen sct_risk_sure19=180
gen sct_risk_sure20=190
gen sct_risk_sure21=170
gen sct_risk_sure22=220
gen sct_risk_sure23=230
gen sct_risk_sure24=210
gen sct_risk_sure25=280
gen sct_risk_sure26=260
gen sct_risk_sure27=270
gen sct_risk_sure28=250
gen sct_risk_sure29=300
gen sct_risk_sure30=290
gen sct_risk_sure31=310


* Label these later payment amount variables
forvalues i=1/31 {
label var sct_risk_sure`i' "Sure amount (risk preferences, staircase)"
}

* Code variables that record individual choices. In raw data 
* 1 means respondent picked payment today and 
* 2 means respondent picked later payment (in 12 months)
* Convert into binary indicator: 0 if today, 1 if later payment chosen

forvalues i=1/31 {
gen sct_riskchoice_sure`i'=.
replace sct_riskchoice_sure`i'=0 if r`i'=="Lottery"
replace sct_riskchoice_sure`i'=1 if r`i'=="Sure payment"
lab var sct_riskchoice_sure`i' "Choice: Sure payment (risk preferences-staircase)"
}

* Generate ID
*drop subject_id
egen subject_id=group(responseid)

* Keep only relevant vars 
keep subject_id responseid sct_amt_12months* sct_choice_later* sct_risk_sure* sct_riskchoice_sure*

* Reshape from wide to long format
reshape long sct_amt_12months sct_choice_later sct_risk_sure sct_riskchoice_sure, i(subject_id) j(timechoice_sc_no)

* Sort
order subject_id sct_amt_12months sct_choice_later sct_risk_sure sct_riskchoice_sure

* Identify switching row
* Risk preferences
order subject_id sct_risk_sure  sct_riskchoice_sure
sort subject_id sct_risk_sure

* For each respondent (subject_id):
* Generade and indicator that identifies the switching row: sure payment
* over lottery chosen)
* This indicator will be zero if the sure payment is never chosen
* It will also be zero if the lottery is always chosen

gen switchrow_sureoverlottery=0

bysort subject_id: replace switchrow_sureoverlottery=1 if sct_riskchoice_sure==1 & sct_riskchoice_sure[_n-1]==0
order switchrow_sureoverlottery
tab switchrow_sureoverlottery

* Same for switching row where switch from late to soon:
gen switchrow_lotteryoversure=0
bysort subject_id: replace switchrow_lotteryoversure=1 if sct_riskchoice_sure==0 & sct_riskchoice_sure[_n-1]==1
tab switchrow_sureoverlottery

order subject_id sct_risk_sure switchrow_sureoverlottery switchrow_lotteryoversure sct_riskchoice_sure
tab switchrow_lotteryoversure

* Generate indicator to code those who always
* select lottery. 
* Create auxiliary variable that counts the number of 
* 1's (sure payment chosen). If that variable is zero,
* the respondent always preferred the lottery
gen alwayslottery=0
label var alwayslottery "Always lottery chosen"
bysort subject_id: egen aux=total(sct_riskchoice_sure)
replace alwayslottery=1 if aux==0 /* Means that never picked later choice 
*/
drop aux
tab alwayslottery

* Generate indicator to code those who always
* select sure payment
gen alwayssure=0
* Create auxiliary indicator that is 0 if sure payment chosen
* and 1 if lottery chosen
recode sct_riskchoice_sure (0=1) (1=0), gen(sct_riskchoice_lottery)
* Test whether lottery ever chosen
bysort subject_id: egen aux=total(sct_riskchoice_lottery)
replace alwayssure=1 if aux==0
label var alwayssure "Always sure payment chosen"
tab alwayssure
drop aux

* Factor var for
* whether always today, switching, or always later

* Create var for switchers
gen sct_risk_type=.
replace sct_risk_type=1 if alwayslottery==1
replace sct_risk_type=2 if alwayslottery==0 & alwayssure==0
replace sct_risk_type=3 if alwayssure==1
label var sct_risk_type "Staircase: Always lottery payment, switches, or always sure payment"
lab define sct_risk_type_lab 1 "Always lottery" 2 "Switches" 3 "Always sure payment"
lab values sct_risk_type sct_risk_type_lab
tab sct_risk_type

* Compute average of lottery and sure payment (Falk)
gen riskacceptance_sc_aux=.
replace riskacceptance_sc_aux=(sct_risk_sure+300*.5)/2 if switchrow_sureoverlottery==1
* Replace all obs with value
bysort subject_id: egen riskacceptance_sc=mean(riskacceptance_sc_aux)
label var riskacceptance_sc "Risk Acceptance (Staircase)"
drop riskacceptance_sc_aux

* Compute average of sure payment chosen and next smallest sure payment not chosen 
gen riskacceptance_bjs_aux=.
replace riskacceptance_bjs_aux=(sct_risk_sure+sct_risk_sure[_n-1])/2 if switchrow_sureoverlottery==1
bysort subject_id: egen riskacceptance_bjs=mean(riskacceptance_bjs_aux)
lab var riskacceptance_bjs "Risk Acceptance (Staircase)"
drop riskacceptance_bjs_aux
pwcorr riskacceptance_sc riskacceptance_bjs, sig

*********
*********
* Time preferences
sort subject_id sct_amt_12months

* For each respondent (subject_id):
* Identify the switching row
* Means that either next lower later payment amount was not chosen (0) 
* and the higher amount was chosen (1)

* Generade and indicator that identifies the switching row: sooner to later (the row where the later payment 
* is chosen)
* This indicator will be zero if the later value is never chosen
* It will also be zero if the later payment is always chosen

gen switchrow_soontolate=0
bysort subject_id: replace switchrow_soontolate=1 if sct_choice_later==1 & sct_choice_later[_n-1]==0
tab switchrow_soontolate

* Same for switching row where switch from late to soon:
gen switchrow_latetosoon=0
bysort subject_id: replace switchrow_latetosoon=1 if sct_choice_later==0 & sct_choice_later[_n-1]==1

order subject_id sct_amt_12months sct_choice_later switchrow_soontolate switchrow_latetosoon
tab switchrow_latetosoon
tab switchrow_soontolate

* Generate indicator to code those who always
* chose payment today
* Create auxiliary variable that counts the number of 
* 1's (later payment choices). If that variable is zero,
* the respondent always preferred the payment today
gen alwaystoday=0
label var alwaystoday "Always payment today chosen"
bysort subject_id: egen aux=total(sct_choice_later)
replace alwaystoday=1 if aux==0 /* Means that never picked later choice 
*/
drop aux
tab alwaystoday

* Generate indicator to code those who always
* chose later payment
gen alwayslater=0
* Create auxiliary indicator that is 0 if later payment chosen
* and 1 if payment today chosen
recode sct_choice_later (0=1) (1=0), gen(sct_choice_today)
* Test whether payment today ever chosen
bysort subject_id: egen aux=total(sct_choice_today)
replace alwayslater=1 if aux==0
label var alwayslater "Always later payment chosen"
tab alwayslater
drop aux

* Factor var for
* whether always today, switching, or always later
* Create var for switchers
gen sct_patience_type=.
replace sct_patience_type=1 if alwaystoday==1
replace sct_patience_type=2 if alwaystoday==0 & alwayslater==0
replace sct_patience_type=3 if alwayslater==1
lab var sct_patience_type "SCT: Always today payment, switches, or always later payment"
lab define sct_patience_type_lab 1 "Always payment today" 2 "Switches" 3 "Always later payment"
lab values sct_patience_type sct_patience_type_lab
tab sct_patience_type

* Generate recoded sct_amt_12months
recode sct_amt_12months ///
(103=214.6) ///
(106.1 = 210.3) ///
(109.2=205.9) ///
(112.4=201.6) ///
(115.6=197.4) ///
(118.8=193.2) ///
(122.1=189.1) ///
(125.4=185) ///
(128.8=180.9) ///
(132.3=176.9) ///
(135.7=172.9) ///
(139.2=169) ///
(142.8=165.1) ///
(146.4=161.3) ///
(150.1=157.5) ///
(153.8=153.8) ///
(157.5=150.1) ///
(161.3=146.4) ///
(165.1=142.8) ///
(169=139.2) ///
(172.9=135.7) ///
(176.9=132.3) ///
(180.9=128.8) ///
(185=125.4) ///
(189.1=122.1) ///
(193.2=118.8) ///
(197.4=115.6) ///
(201.6=112.4) ///
(205.9=109.2) ///
(210.3=106.1) ///
(214.6=103) ///
, gen(sct_amt_12months_rev)

/*
* Compute average of payment today and later payment
gen impatience_sc_aux=.
replace impatience_sc_aux=(sct_amt_12months+100)/2 if switchrow_soontolate==1
bysort subject_id: egen impatience_sc=mean(impatience_sc_aux)
lab var impatience_sc "Impatience (Staircase)"
drop impatience_sc_aux
gen patience_sc=-1*impatience_sc
lab var patience_sc "Patience (Staircase)"

* Compute average of later payment chosen and later payment not chosen
gen impatience_bjs_aux=.
replace impatience_bjs_aux=(sct_amt_12months+sct_amt_12months[_n-1])/2 if switchrow_soontolate==1
bysort subject_id: egen impatience_bjs=mean(impatience_bjs_aux)
lab var impatience_bjs "Impatience (Staircase, BJS)"
drop impatience_bjs_aux
gen patience_bjs=-1*impatience_bjs
lab var patience_bjs "Patience (Staircase, BJS)"
*/
* Compute average of payment today and later payment


* Compute average of later payment chosen and later payment not chosen
gen patience_bjs_aux=.
replace patience_bjs_aux=(sct_amt_12months_rev+sct_amt_12months_rev[_n-1])/2 if switchrow_soontolate==1
bysort subject_id: egen patience_bjs=mean(patience_bjs_aux)
lab var patience_bjs "Patience (Staircase, BJS)"

gen patience_sc_aux=.
replace patience_sc_aux=(sct_amt_12months_rev+100)/2 if switchrow_soontolate==1
bysort subject_id: egen patience_sc=mean(patience_sc_aux)
lab var patience_sc "Patience (Staircase)"

su patience_sc, det
gen patience_sc_high=.
replace patience_sc_high=0 if patience_sc<`r(p50)'
replace patience_sc_high=1 if patience_sc>=`r(p50)' & patience_sc!=.

pwcorr patience_sc patience_bjs, sig

*** Generate second time and risk staircase measure
* with missings imputed
* riskacceptance_sc and riskacceptance_bjs
* Min is 10 and max is 310
* Time: Min is 103 and Max is 214.6

* 1) Imputed time preference measure
* Time: Min is 103 and max is 214.6
gen patience_sc_imp=patience_sc
* If always today payment, very impatient, impute min of 103 
replace patience_sc_imp=103 if alwaystoday==1
* Impute minimum amount of 214.6 if always later payment
* which means that very patient. 
* Multiply by -1 so that higher values mean more patient   
replace patience_sc_imp=214.6 if alwayslater==1

* 2) Imputed risk preference measure
* Time: Min is 10 and max is 310
gen riskacceptance_sc_imp=riskacceptance_sc
* If always safe payment, very risk-averse, impute min of 10 
replace riskacceptance_sc_imp=10 if alwayssure==1 

* If always lottery, impute max of 310 of safe payment
* to indicate that very risk-acceptant   
replace riskacceptance_sc_imp=310 if alwayslottery==1

* keep only one observation per respondent
bysort subject_id: gen aux_n=_n
keep if aux_n==1

keep subject_id responseid patience_sc patience_sc_high patience_sc_imp patience_bjs sct_risk_type sct_patience_type riskacceptance_sc riskacceptance_sc_imp riskacceptance_bjs
order responseid
sort responseid
compress
save "$data/timerisk_sc_formerge.dta", replace

